package com.hqd.ch03.v46.core;

import java.util.function.Function;

public interface AttributeAccessor {
    void setAttribute(String name, Object value);

    Object getAttribute(String name);

    @SuppressWarnings("unchecked")
    default <T> T computeAttribute(String name, Function<String, T> computeFunction) {
        Object value = getAttribute(name);
        if (value == null) {
            value = computeFunction.apply(name);
        }
        return (T) value;
    }

    Object removeAttribute(String name);

    boolean hasAttribute(String name);

    String[] attributeNames();
}
